package com.atguigu.pratice;

import java.util.concurrent.TimeUnit;

//练习；创建两个分线程，其中一个线程遍历100以内的偶数，另一个线程遍历100以内的奇数
public class Demo{

    public static void main(String[] args) {
//        PrintDemo printDemo = new PrintDemo();
//        printDemo.start();
//        new PrintDemo().start();
         Thread t1 = new Thread(){
            public void run(){
                for (int i = 0; i < 100; i++) {
                    if(i%2==0){
                        System.out.println(Thread.currentThread().getName()+"\t"+i);
                    }
                }
            }
        };
         t1.start();
        //线程睡眠几秒
        try {
            TimeUnit.SECONDS.sleep(1);} catch (InterruptedException e) {throw new RuntimeException(e);}
        Thread t2 = new Thread(){
            public void run(){
                for (int i = 0; i < 100; i++) {
                    if(i%2!=0){
                        System.out.println(Thread.currentThread().getName()+"\t"+i);
                    }
                }
            }
        };
        t2.start();





//        PrintDemo1 printDemo1 = new PrintDemo1();
//        printDemo1.start();

        }
    }


class PrintDemo extends Thread{
    //重写run方法
    @Override
    public void run (){
        for (int i = 0; i < 100; i++) {
            if(i%2==0){
                System.out.println(Thread.currentThread().getName()+"\t"+i);
            }
        }
    }
}
class PrintDemo1 extends Thread{
    //重写run方法
    @Override
    public void run (){
        for (int i = 0; i < 100; i++) {
            if(i%2!=0){
                System.out.println(Thread.currentThread().getName()+"\t"+i);
            }
        }
    }
}
